using System;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Collections;
using System.Drawing;
using System.Workflow.ComponentModel;
using System.Workflow.ComponentModel.Design;
using System.Workflow.ComponentModel.Compiler;
using System.Workflow.ComponentModel.Serialization;
using System.Workflow.Runtime;
using System.Workflow.Activities;
using System.Workflow.Activities.Rules;
using UIProcessSchemaObjects;

namespace UIProcessActivities
{
    [Designer(typeof(FindFormResourceDesigner), typeof(IDesigner))]
    public partial class FindFormResource : SequenceActivity
    {
        public FindFormResource()
        {
            InitializeComponent();
        }

        public static DependencyProperty FormResourceProperty = System.Workflow.ComponentModel.DependencyProperty.Register("FormResource", typeof(UIProcessSchemaObjects.FormResource), typeof(FindFormResource));

        [Description("FormResource")]
        [Category("Output")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public UIProcessSchemaObjects.FormResource FormResource
        {
            get
            {
                return ((UIProcessSchemaObjects.FormResource)(base.GetValue(FindFormResource.FormResourceProperty)));
            }
            set
            {
                base.SetValue(FindFormResource.FormResourceProperty, value);
            }
        }

        public static DependencyProperty SearchStringProperty = System.Workflow.ComponentModel.DependencyProperty.Register("SearchString", typeof(string), typeof(FindFormResource));

        [Description("Form Resource Name Search String")]
        [Category("Input")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public string SearchString
        {
            get
            {
                return ((string)(base.GetValue(FindFormResource.SearchStringProperty)));
            }
            set
            {
                base.SetValue(FindFormResource.SearchStringProperty, value);
            }
        }

        public static DependencyProperty FormProperty = System.Workflow.ComponentModel.DependencyProperty.Register("Form", typeof(UIProcessSchemaObjects.Form), typeof(FindFormResource));

        [Description("The Form loaded by the activity")]
        [Category("Input")]
        [Browsable(true)]
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Visible)]
        public UIProcessSchemaObjects.Form Form
        {
            get
            {
                return ((UIProcessSchemaObjects.Form)(base.GetValue(FindFormResource.FormProperty)));
            }
            set
            {
                base.SetValue(FindFormResource.FormProperty, value);
            }
        }


        protected override ActivityExecutionStatus Execute(ActivityExecutionContext executionContext)
        {
            foreach (UIProcessSchemaObjects.FormResource objTemp in this.Form.FormResources)
            {
                if (objTemp.Name == this.SearchString)
                {
                    this.FormResource = objTemp;
                    break;
                }
            }

            return ActivityExecutionStatus.Closed;
        }
    }
}
